new Vue({
    el: '#app',
    data() {
        return {
            form: {
                
            },
            purchaseOrderData: {},
            salesOrderData: {},
            formData: {},
            loading: false,
            disabled: true
        }
    },
    mounted() {
        this.formData = JSON.parse(sessionStorage.getItem('fillorder'))
        console.log(this.formData)
        // this.form.Receipt_Date = getYMDHMSDate()
        // this.form.Receipt_Type == '0' ? this.form.Receipt_Name = '仓库' : this.form.Receipt_Name = '店铺'
        // this.form.Children.sales_receipt_detail[0].Order_Type == '1' ? this.form.Children.sales_receipt_detail[0].Order_Name = '企业' : this.form.Children.sales_receipt_detail[0].Order_Name = '用户'
        // this.form.Store_Name = this.formData.Warehouse_Name
        // this.form.Enterprise_Info_SerialNumber = this.formData.Enterprise_Info_SerialNumber
        // this.form.Children.sales_receipt_detail[0].Sales_Order_SerialNumber = this.formData.Purchase_Order_SerialNumber
        // this.form.Children.sales_receipt_detail[0].Article_Name = this.formData.Article_Name
        // this.form.Children.sales_receipt_detail[0].Receipt_Quantity = this.formData.Delivery_Quantity
        // if (this.formData.Purchase_Order_SerialNumber.indexOf("M") != -1) {
        //     this.purchaseOrder(this.formData.Purchase_Order_SerialNumber)
        // } else {
        //     this.salesOrder(this.formData.Purchase_Order_SerialNumber)
        // }
       
        // if (this.form.Children.sales_receipt_detail.length != 0) {
        //     this.disabled = false
        // }
    },
    methods: {
        SubmitChange(row, Row_Status, message = '成功') {//修改查到的原值并提交
            let _this = this
            let data = {}
            if (this.formData.Purchase_Order_SerialNumber.indexOf("M") != -1) {
                this.purchaseOrderData.Row_Status = '4'
                row.Row_Status = Row_Status//初级
                // row.Logistics_Number = this.form.Children.sales_receipt_detail[0].Logistics_Number
                // this.purchaseOrderData.Logistics_Number = this.form.Children.sales_receipt_detail[0].Logistics_Number
                row.Logistics_Date = getYMDHMSDate()
                this.purchaseOrderData.Logistics_Date = getYMDHMSDate();
                data = {
                    Data: JSON.stringify({
                        Modify: { delivery_order: [row], purchase_order: [_this.purchaseOrderData] }
                    })
                }
            } else {
                this.salesOrderData.Row_Status = '6'
                row.Row_Status = Row_Status
                // row.Logistics_Number = this.form.Children.sales_receipt_detail[0].Logistics_Number
                // this.salesOrderData.Logistics_Number = this.form.Children.sales_receipt_detail[0].Logistics_Number
                row.Logistics_Date = getYMDHMSDate()
                this.salesOrderData.Logistics_Date = getYMDHMSDate();
                data = {
                    Data: JSON.stringify({
                        Modify: { delivery_order: [row], sales_order_detail: [_this.salesOrderData] }
                    })
                }
            }
            $.ajax({
                type: 'POST',
                url: DomainName + "/getEditAction?token=" + $.cookie("token"),
                data,
                success: function (res) {
                    console.log(res)
                    if (res.Status == 'success') {
                        _this.$message({
                            message: '提交成功',
                            type: 'success'
                        });
                        _this.loading = false
                        window.history.go(-1)
                    }
                },
                complete: function (XMLHttpRequest) {
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = absolutepath + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                dataType: "json"
            });
        },
        submitForm() {
            // if (this.form.Children.sales_receipt_detail[0].Logistics_Numbers == '') {
            //     this.$message({
            //         message: '请填写物流单号',
            //         type: 'error'
            //     });
            //     return
            // }
            let _this = this
            _this.loading = true
            // this.form.Receipt_Type = '0'
            // this.form.Children.sales_receipt_detail[0].Order_Type = '1'
            // this.form.Store_SerialNumber = this.formData.Warehouse_SerialNumber
            // this.form.Children.sales_receipt_detail[0].Article_SerialNumber = this.formData.Article_SerialNumber
            // console.log(this.form)
            $.ajax({
                type: 'GET',
                url:' https://marketingservice.ediblefungus.cn/Order/setReduceInventoryAction',
                data:{
                    token:$.cookie('token'),
                    Delivery_Order_SerialNumber:'',
                    Logistics_Code:'',
                    Logistics_Number:''
                },
                success: function (res) {
                    console.log('copy数据11111111',res)
                    if (res.Status == 'success') {
                        _this.SubmitChange(_this.formData, '1', '发货成功')
                    }else{
                        _this.loading = false
                        _this.$message.error(res.Cause)
                    }
                },
                complete: function (XMLHttpRequest) {
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = absolutepath + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                dataType: "json"
            });
        },
        purchaseOrder(Primary_Key) {
            console.log(Primary_Key)
            let _this = this
            $.ajax({
                type: 'POST',
                url: DomainName + "/getInquiryIDOriginal?token=" + $.cookie("token"),
                data: {
                    Primary_Key_Name: 'Purchase_Order_SerialNumber',
                    Primary_Key,
                    Data: 'purchase_order',
                    isNullEnterprise: true
                },
                success: function (res) {
                    console.log(res)
                    _this.purchaseOrderData = res[0]
                },
                complete: function (XMLHttpRequest) {
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = absolutepath + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                dataType: "json"
            });
        },
        salesOrder(Primary_Key) {
            console.log(Primary_Key)
            let _this = this
            $.ajax({
                type: 'POST',
                url: DomainName + "/getInquiryIDOriginal?token=" + $.cookie("token"),
                data: {
                    Primary_Key_Name: 'Sales_Order_Detail_SerialNumber',
                    Primary_Key,
                    Data: 'sales_order_detail',
                    isNullEnterprise: true
                },
                success: function (res) {
                    console.log(res)
                    _this.salesOrderData = res[0]
                },
                complete: function (XMLHttpRequest) {
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = absolutepath + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                dataType: "json"
            });
        }
    },
})